package com.leetcode.bfs;

import java.util.ArrayList;
import java.util.List;

/**
 * 通过DFS的思路解决这类问题：跟节点-》右子树=》左子书
 */
public class Leetcode199 {
    private List<Integer> res = new ArrayList<>();
    public List<Integer> rightSideView(TreeNode root) {
        if (root == null) {
            return res;
        }
        dfs(0, root);
        return res;
    }

    private void dfs(int depth, TreeNode node) {
        // 退出条件
        if (node == null) {
            return;
        }

        if (res.size() == depth) {
            res.add(node.val);
        }

        depth++;

        dfs(depth, node.right);
        dfs(depth, node.left);
    }
}
